import Vue from "vue";
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
    mode: 'history', // 开启历史路由,可去除路由中的#号
    routes: [
        {
            path: '/',
            component: () => import('@/components/layout'),
            children: [
                {
                    path: '', // http://localhost:7000
                    component: () => import('@/views/auth/login')
                },
                {
                    path: '/retrieve', // http://localhost:7000/retrieve
                    component: () => import('@/views/auth/retrieve')
                }
            ]
        },
        {
            path: '/refresh',
            component: () => import('@/components/layout'), // 引入此布局
            children: [
                {
                    path: '', // http://localhost:7000
                    component: () => import('@/views/auth/refresh')
                }
            ]
        }
    ]
})

import store from "@/store";

// 路由拦截,每次路由跳转都会通过这个拦截器
router.beforeEach((to, from, next) => {
    if (to.path === '/logout') {
        // 退出操作
        store.dispatch('UserLogout', to.query.redirectURL)
    } else {
        next() // 放行
    }
})

export default router;
